package cvc.framework.controller;


import cvc.framework.entity.WebSocketMessage;
import cvc.framework.result.RestMessage;
import cvc.framework.result.RestResult;
import cvc.framework.service.TypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Types")
public class TypeController {
    @Autowired
    TypesService typesService;

    //获取所有类型信息
    @RequestMapping("/getTypes")
    public RestResult getTypes(String targetName, String uuid) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = typesService.getTypes(targetName, uuid);
        return res;
    }

    //通过id获取类型信息
    @RequestMapping("/getTypeById")
    public RestResult getTypeById(String targetName, String uuid, String id) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = typesService.getTypeById(targetName, id, uuid);
        return res;
    }

    //添加类型信息
    @PostMapping(value = "/addType")
    public RestResult addType(@RequestBody WebSocketMessage message) {
        System.out.println(message.toString());
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = typesService.addType(message);
        return res;
    }

    //修改类型信息
    @PostMapping(value = "/updateType")
    public RestResult updateType(@RequestBody WebSocketMessage message) {
        System.out.println(message.toString());
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = typesService.updateType(message);
        return res;
    }

    //删除类型信息
    @RequestMapping("/deleteType")
    public RestResult deleteType(String targetName, String uuid, String id) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = typesService.deleteType(targetName, uuid, id);
        return res;
    }
}
